<%@ page contentType="text/html;charset=UTF-8" %>
<%@ page import="java.util.*" %>
<%@ page import="org.jbpm.graph.def.*" %>
<%@ page import="org.jbpm.graph.exe.*" %>
<%@ page import="org.jbpm.db.*" %>
<%@ page import="org.jbpm.*" %>
<%@ page import="com.gzgi.framework.context.*" %>
<%@ page import="com.gzgi.workflow.jbpm.model.*" %>
<%@ page import="com.gzgi.workflow.jbpm.context.*" %>
<%@ page import="com.gzgi.workflow.jbpm.service.*" %>
<%@ page import="com.gzgi.workflow.jbpm.dao.*" %>
<%@ page import="com.gzgi.framework.util.*" %>
<%@ page import="org.apache.commons.lang.*" %>
<%@ include file="/pages/system/checkAdmin.jsp"%>
<%
         System.out.println("-----------------------------------------------------------------------------------------");
		 System.out.println("-----------------------------------------------------------------------------------------");
		 System.out.println("-----------------------------------------------------------------------------------------");
         String q = request.getParameter("q");
		 String actorId = request.getParameter("actorId");
		 String processName = request.getParameter("processName");
         if(StringUtils.isEmpty(actorId)){
			 actorId = "joy";
		 }
		 if(StringUtils.isEmpty(processName)){
			 processName="OrderProcess";
		 }
         TaskDAO taskDAO = null;
		 JbpmContext jbpmContext = null;
		try {
			JbpmConfiguration jbpmConfiguration = JbpmConfiguration.getInstance();
			jbpmContext = jbpmConfiguration.createJbpmContext();
			taskDAO = (TaskDAO)com.gzgi.framework.context.ContextFactory.getBean("taskDAO");
			
			if (jbpmContext.getSession() != null) {
                if("1".equals(q)){
					List taskItems = taskDAO.getAllTaskItems(jbpmContext);
                    if(taskItems != null && taskItems.size() > 0){
						out.println("taskItems :"+taskItems);
						out.println("taskItems size:"+taskItems.size());
					}
				} else  if("2".equals(q)){
					List taskItems = taskDAO.getTaskItems(jbpmContext, actorId);
                    if(taskItems != null && taskItems.size() > 0){
						out.println("taskItems size:"+taskItems.size());
						out.println("<br><br>taskItems :"+taskItems);
					}
				} else  if("3".equals(q)){
					List actorIds = new ArrayList();
					actorIds.add(actorId);
					List taskItems = taskDAO.getTaskItems(jbpmContext, actorIds);
                    if(taskItems != null && taskItems.size() > 0){
						out.println("taskItems size:"+taskItems.size());
						out.println("<br><br>taskItems :"+taskItems);
					}
				} else  if("4".equals(q)){
					List actorIds = new ArrayList();
					actorIds.add(actorId);
					List taskItems = taskDAO.getTaskItems(jbpmContext, actorId, "20");
                    if(taskItems != null && taskItems.size() > 0){
						out.println("taskItems size:"+taskItems.size());
						out.println("<br><br>taskItems :"+taskItems);
					}
				} else  if("5".equals(q)){
					List actorIds = new ArrayList();
					actorIds.add(actorId);
					List taskItems = taskDAO.getTaskItems(jbpmContext, actorIds, "20");
                    if(taskItems != null && taskItems.size() > 0){
						out.println("taskItems size:"+taskItems.size());
						out.println("<br><br>taskItems :"+taskItems);
					}
				} else  if("6".equals(q)){
					List actorIds = new ArrayList();
					actorIds.add(actorId);
					List taskItems = taskDAO.getTaskItemsByProcessInstanceId(jbpmContext, "20");
                    if(taskItems != null && taskItems.size() > 0){
						out.println("taskItems size:"+taskItems.size());
						out.println("<br><br>taskItems :"+taskItems);
					}
				} else  if("7".equals(q)){
					List actorIds = new ArrayList();
					actorIds.add(actorId);
					List taskItems = taskDAO.getTaskItemsByProcessName(jbpmContext, processName);
                    if(taskItems != null && taskItems.size() > 0){
						out.println("taskItems size:"+taskItems.size());
						out.println("<br><br>taskItems :"+taskItems);
					}
				} else  if("8".equals(q)){
					List actorIds = new ArrayList();
					actorIds.add(actorId);
					List taskItems = taskDAO.getTaskItemsByProcessName(jbpmContext, processName, actorId);
                    if(taskItems != null && taskItems.size() > 0){
						out.println("taskItems size:"+taskItems.size());
						out.println("<br><br>taskItems :"+taskItems);
					}
				} else  if("9".equals(q)){
					List actorIds = new ArrayList();
					actorIds.add(actorId);
					List taskItems = taskDAO.getTaskItemsByProcessName(jbpmContext, processName, actorIds);
                    if(taskItems != null && taskItems.size() > 0){
						out.println("taskItems size:"+taskItems.size());
						out.println("<br><br>taskItems :"+taskItems);
					}
				} else  if("a".equals(q)){
					List actorIds = new ArrayList();
					actorIds.add(actorId);
					List taskItems = taskDAO.getFinishedTaskItems(jbpmContext, actorId);
                    if(taskItems != null && taskItems.size() > 0){
						out.println("taskItems size:"+taskItems.size());
						out.println("<br><br>taskItems :"+taskItems);
					}
				} else  if("b".equals(q)){
					List actorIds = new ArrayList();
					actorIds.add(actorId);
					List taskItems = taskDAO.getFinishedTaskItems(jbpmContext, processName, actorId);
                    if(taskItems != null && taskItems.size() > 0){
						out.println("taskItems size:"+taskItems.size());
						out.println("<br><br>taskItems :"+taskItems);
					}
				}else  if("x".equals(q)){
					List actorIds = new ArrayList();
					actorIds.add(actorId);
					Collection rows = taskDAO.getFinishedProcessInstanceIds(jbpmContext, actorIds);
                    if(rows != null && rows.size() > 0){
						out.println("rows size:"+rows.size());
						out.println("<br><br>rows :"+rows);
					}
				}else  if("y".equals(q)){
					List actorIds = new ArrayList();
					actorIds.add(actorId);
					Collection rows = taskDAO.getProcessInstanceIds(jbpmContext, processName);
                    if(rows != null && rows.size() > 0){
						out.println("rows size:"+rows.size());
						out.println("<br><br>rows :"+rows);
					}
				}else  if("z".equals(q)){
					List processInstanceIds = new ArrayList();
					List actorIds = new ArrayList();
					actorIds.add(actorId);
					Collection rowsxy = taskDAO.getProcessInstanceIds(jbpmContext, processName);
					if (rowsxy != null) {
						out.println("all rows:"+rowsxy);
						Collection rows = taskDAO.getFinishedProcessInstanceIds(jbpmContext, actorIds);
						if (rows != null && rows.size() > 0) {
							System.out.println("actor rows:"+rows);
							Iterator iterator = rowsxy.iterator();
							while (iterator.hasNext()) {
								String processInstanceId = (String) iterator.next();
								if (rows.contains(processInstanceId)) {
									processInstanceIds.add(processInstanceId);
								}
							}
						}
					}
                    if(processInstanceIds != null && processInstanceIds.size() > 0){
						out.println("processInstanceIds size:"+processInstanceIds.size());
						out.println("<br><br>processInstanceIds :"+processInstanceIds);
					}
				}
			}
		}catch (Exception ex) {
			ex.printStackTrace();
		}  finally {
			Context.close(jbpmContext);
		}
%>